package com.xbongbong.saas.enums;

import com.xbongbong.i18n.util.I18nMessageUtil;
import java.util.ArrayList;
import java.util.List;
import lombok.Getter;

/**
 * 呼叫结果枚举信息
 *
 * @author 章华隽
 * @mail nefeed@163.com
 * @time 2017-12-04 11:20
 */
@Getter
public enum CallLogResultEnum {
    /**
     * 呼叫结果枚举
     */
    FAIL(0, "enum.callLogResult.name.fail", "FAIL"),
    SUCCESS(1, "enum.callLogResult.name.success", "SUCCESS"),
    UN_SYNCED(2, "enum.callLogResult.name.un_synced", "UN_SYNCED"),

    UNKNOWN(XbbRefTypeEnum.UNKNOWN.getCode(), "enum.callLogResult.name.unknown", "UNKNOWN");

    /**
     * 枚举值 --
     */
    private final int code;

    /**
     * 枚举信息--中文名称
     */
    private final String name;

    /**
     * 枚举描述 --英文名称
     */
    private final String alias;

    /**
     * 构造一个枚举对象
     *
     * @param code  枚举值
     * @param name  枚举类型名
     * @param alias 枚举类型英文别名
     */
    CallLogResultEnum(int code, String name, String alias) {
        this.code = code;
        this.name = name;
        this.alias = alias;
    }

    /**
     * 通过枚举 alias 获得枚举
     *
     * @param alias 枚举类型英文别名
     * @return CallLogResultEnum
     */
    public static CallLogResultEnum getByAlias(String alias) {
        for (CallLogResultEnum cacheCode : values()) {
            if (cacheCode.getAlias().equals(alias)) {
                return cacheCode;
            }
        }
        return UNKNOWN;
    }

    /**
     * 通过枚举 code 获得枚举
     *
     * @param code 枚举类型英文别名
     * @return CallLogResultEnum
     */
    public static CallLogResultEnum getByCode(Integer code) {
        for (CallLogResultEnum cacheCode : values()) {
            if (code.equals(cacheCode.getCode())) {
                return cacheCode;
            }
        }
        return UNKNOWN;
    }

    /**
     * 获取全部枚举
     *
     * @return List<CallLogResultEnum>
     */
    public List<CallLogResultEnum> getAllEnum() {
        List<CallLogResultEnum> list = new ArrayList<>();
        for (CallLogResultEnum cache : values()) {
            if (cache == UNKNOWN) {
                continue;
            }
            list.add(cache);
        }
        return list;
    }

    /**
     * 获取全部枚举值
     *
     * @return List<String>
     */
    public List<String> getAllEnumAlis() {
        List<String> list = new ArrayList<>();
        for (CallLogResultEnum cache : values()) {
            if (cache == UNKNOWN) {
                continue;
            }
            list.add(cache.getAlias());
        }
        return list;
    }

    public String getName() {
        return I18nMessageUtil.getMessage(name);
    }
}
